package cn.bs.busuo.front.content.controller;

import cn.bs.busuo.common.pojo.authentication.CurrentPrincipal;
import cn.bs.busuo.common.web.JsonResult;
import cn.bs.busuo.front.content.pojo.param.HotelArticleAddNewParam;
import cn.bs.busuo.front.content.pojo.param.HotelArticleUpDateParam;
import cn.bs.busuo.front.content.pojo.vo.UserContentHotelArticleByIdVO;
import cn.bs.busuo.front.content.service.UserHotelArticleService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * @author: Feng
 * @since: 2023/12/8
 */
@RestController
@Slf4j
@RequestMapping("/content/hotelArticle")
@Api(tags = "6.用户酒店文章")
public class UserHotelArticleController {

    @Autowired
    private UserHotelArticleService userHotelArticleService;

    @PostMapping("/addNew/{id}")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("发布酒店文章")
    @ApiOperationSupport(order = 100)
    public JsonResult addNewHotelArticle(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                         @Valid HotelArticleAddNewParam hotelArticleAddNewParam,@PathVariable @ApiIgnore("id") Long id) {
        userHotelArticleService.addNewHotelArticle(currentPrincipal,hotelArticleAddNewParam,id);
        return JsonResult.ok();
    }

    @PostMapping("/deleteArticle")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("删除酒店文章")
    @ApiOperationSupport(order = 200)
    public JsonResult deleteHotelArticle(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,Long id) {
        userHotelArticleService.deleteArticle(currentPrincipal,id);
        return JsonResult.ok();
    }

    @GetMapping("/selectByHotelId/{id}")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("根据酒店Id查看酒店文章")
    @ApiOperationSupport(order = 300)
    public JsonResult hotelArticleById(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@PathVariable @ApiIgnore("id") Long id) {
        return JsonResult.ok(userHotelArticleService.selectHotelArticleByHotelId(id));
    }

    @GetMapping("/selectHotelArticleById/{id}")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("查看酒店某篇文章详情")
    @ApiOperationSupport(order = 400)
    public JsonResult selectHotelArticleDetailById(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                                         @PathVariable @ApiIgnore("id") Long id) { //
        return JsonResult.ok(userHotelArticleService.selectHotelArticleDetailById(id));
    }

    @PostMapping("/selectHotelArticleById/upCount/{id}")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("查看酒店文章详情并好评")
    @ApiOperationSupport(order = 500)
    public JsonResult hotelArticleDetailIncreaseUpCount(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@PathVariable @ApiIgnore Long id) {
        userHotelArticleService.increaseUpCount(id);
        return JsonResult.ok();
    }

    @PostMapping("/selectHotelArticleById/downCount/{id}")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("查看酒店文章详情并差评")
    @ApiOperationSupport(order = 600)
    public JsonResult hotelArticleDetailIncreaseDownCount(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,@PathVariable @ApiIgnore Long id) {
        userHotelArticleService.increaseDownCount(id);
        return JsonResult.ok();
    }

    @GetMapping("/userListHotelArticle")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("查看自己的酒店文章")
    @ApiOperationSupport(order = 700)
    public JsonResult userListHotelArticle(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
        return JsonResult.ok(userHotelArticleService.selectUserListHotelArticle(currentPrincipal.getUsername()));
    }

    @PostMapping("/userListHotelArticle/upDateHotelArticle/{id}")
    @PreAuthorize("hasAuthority('/account/user/normal')")
    @ApiOperation("修改自己的酒店文章")
    @ApiOperationSupport(order = 800)
    public JsonResult upDateHotelArticle(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal, @PathVariable @ApiIgnore Long id, HotelArticleUpDateParam hotelArticleUpDateParam) {
        userHotelArticleService.upDateHotelArticle(currentPrincipal.getUsername(),id,hotelArticleUpDateParam);
        return JsonResult.ok();
    }

}
